import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Solution {
    public List<List<Integer>> fourSum(int[] nums, int target){
        List<List<Integer>> ret = new ArrayList<>();

        //第一步，排序
        Arrays.sort(nums);

        //利用双指针解决
        int len = nums.length;
        for (int i = 0; i < len; ) {//固定第一个数
            for (int j = i+1; j < len; ) {//固定第二个数
                int left = j+1,right = len-1;
                long aim = (long)target-nums[i]-nums[j];
                while(left < right){
                    int sum = nums[left] + nums[right];
                    if(sum < aim) left++;
                    else if (sum > aim) right--;
                    else {
                        ret.add(Arrays.asList(nums[i],nums[j],nums[left++],nums[right--]));
                        while(left<right && nums[left]==nums[left-1]) left++;
                        while(left<right && nums[right]==nums[right+1]) right--;
                    }
                }
                j++;
                while(j<len && nums[j]==nums[j-1]) j++;
            }
            i++;
            while(i<len && nums[i]==nums[i-1]) i++;
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = in.nextInt();
            }
            int target = in.nextInt();
            Solution solution = new Solution();
            List<List<Integer>> result = solution.fourSum(arr,target);
            for(List<Integer> list : result){
                System.out.print(list+" ");
            }
        }
    }
}
